/*
 * TODO
 */
package com.xtrip.adm.stat.data;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;

import com.xtrip.common.BasicConstant;
import com.xtrip.common.TcConstant;
import com.xtrip.hotel.model.Hotel;
import com.xtrip.util.IdGenerator;
import com.xtrip.util.parse.xml.XtripDocumentHelper;

/**
 * @project xtrip
 * @author shiming.yao
 * @time 2013-6-5
 */
/*
 * 1.1.1酒店更新数据
 * hotel-goe-cn.xml
 * */
public class TcHotelList {

	private List<Hotel> hList = null;
	/**
	 * 
	 */
	public TcHotelList() {
		hList = new ArrayList<Hotel>();
	}
	public void parseAdd(String file){
		parse(file, TcConstant.HOTEL_OPERATION_ADD);
	}
	public void parseUpdate(String file){
		parse(file, TcConstant.HOTEL_OPERATION_UP);
	}
	public void parse(String file,int operation){
		try {
			Document doc = XtripDocumentHelper.readFile(file);
			Element root = doc.getRootElement();
			
			List<Element> hotelList = root.elements();
			for(Element hotel : hotelList){
				List<Element> items = hotel.elements();
				Element flagEl = hotel.element("flag");
				Element mdateEl = hotel.element("modifyDate");
				Element idEl = hotel.element("hotelId");
				Element nameEl = hotel.element("hotelName");
				
				if(flagEl.getStringValue().equals("0")) continue;
				String upTime = mdateEl.getStringValue();
				Hotel h = new Hotel();
				h.setId(IdGenerator.generateId(BasicConstant.PREFIX_HOTEL));
				h.setTcUpTime(upTime);
				h.setTcHId(idEl.getStringValue());
				h.setName(nameEl.getStringValue());
				
				hList.add(h);
			}
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public List<Hotel> gethList() {
		return hList;
	}
	public void sethList(List<Hotel> hList) {
		this.hList = hList;
	}

}
